package com.njit.WeStudy.dao;

import com.njit.WeStudy.dataobject.JoinGroup;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

public interface JoinGroupMapper {
    @Delete({
        "delete from join_group",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into join_group (user_id, ",
        "group_id, join_time, ",
        "leave_time, is_top)",
        "values (#{userId,jdbcType=INTEGER}, ",
        "#{groupId,jdbcType=INTEGER}, now(), ",
        "#{leaveTime,jdbcType=TIMESTAMP}, #{isTop,jdbcType=BIT})"
    })
    int insert(JoinGroup record);

    @Select({
        "select",
        "id, user_id, group_id, join_time, leave_time, is_top",
        "from join_group",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results(id = "resultMap",value = {
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
        @Result(column="group_id", property="groupId", jdbcType=JdbcType.INTEGER),
        @Result(column="join_time", property="joinTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="leave_time", property="leaveTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="is_top", property="isTop", jdbcType=JdbcType.BIT)
    })
    JoinGroup selectByPrimaryKey(Integer id);

    @Select({
        "select",
        "id, user_id, group_id, join_time, leave_time, is_top",
        "from join_group"
    })
    @ResultMap("resultMap")
    List<JoinGroup> selectAll();

    @Update({
        "update join_group",
        "set user_id = #{userId,jdbcType=INTEGER},",
          "group_id = #{groupId,jdbcType=INTEGER},",
          "leave_time = #{leaveTime,jdbcType=TIMESTAMP},",
          "is_top = #{isTop,jdbcType=BIT}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(JoinGroup record);
}